<#include '/admin/header.html' > 
<style>
 .layui-btn{
  background:#1E9FFF;
  }
</style>
<div  class="admin-main">
   <div>
        <!--提示区域  -->
        <div class="page_explain">
            <h2>操作提示</h2>
            <ul>
                <li><span>·</span>团购管理分为团购活动、团购地区和团购分类</li>
                <li><span>·</span>团购活动有添加团购活动，管理商品，删除团购活动,添加团购商品功能</li>
                <li><span>·</span>团购地区可对团购活动设置团购此活动可以参加的地区</li>
                <li><span>·</span>团购分类设置团购商品所属类别</li>
            </ul>
        </div>
        <!--按钮操作  -->
        <div class="table_control">
            <div class="table_opera">
                <button type="button" id="addgroupbuy" title="新增" class="layui-btn layui-btn-primary" ><i class="icon iconfont icon-llalbumshopselectorcreate"></i></button>
                <button type="button" title="提示" class="layui-btn layui-btn-primary" id="explain"><i class="icon iconfont icon-tishi1"></i></button>
            </div>
        </div>
   </div>
   <!--表格区域  -->
   <form id="groupbuyform">
    <table id="groupbuy" class="layui-table site-table table-hover" width="100%" lay-skin="line">
        <thead>
          <tr>
            <th><input type='checkbox'  class='btn-checkall fly-checkbox' id='selected-all'></th>
            <th>活动名称</th>
            <th>开始时间</th>
            <th>结束时间</th>
            <th>状态</th>
            <th>操作</th>
          </tr>
        </thead>
    </table>
   </form>
</div>

<script type="text/javascript">
var table;
$(function(){
	 table = $('#groupbuy').DataTable({
		"language": {
	        "url": "${staticserver}/media/zh_CN.txt"
	    },
	    "processing": true,
	    "serverSide": true,
	    "ordering": false,
	    "searching": false,
	    "lengthChange": false,
	    ajax: {
	        //指定数据源
	        type:"post",
	        url: '${ctx}/shop/admin/group-buy-act/list-json.do',
	    },
	    columns: [ //定义列
            {"data": function (obj) {
                return '<input type="checkbox" name="act_id" class="fly-checkbox" value=' + obj.act_id + '>';
            		}},
	        {data: "act_name"},
	        {data: null,"render": function(data, type, row) {
	        	if(data.start_time==null){
	        		return " ";
	        	}else{
	        		return getFormatDateByLong(data.start_time, "yyyy-MM-dd hh:mm:ss");
	        	}
	       	}},
	        {data: null,"render": function(data, type, row) {
	        	if(data.end_time==null){
	        		return " ";
	        	}else{
	        		return getFormatDateByLong(data.end_time, "yyyy-MM-dd hh:mm:ss");
	        	}
	       	}},
	        {data: null,"render": function(data, type, row) {
	        	if(data.act_status==0){
	        		return "未开始";
	        	}else if(data.act_status==1){
	        		return "已开始";
	        	}else if(data.act_status==2){
	        		return "已结束";
	        	}
	       	}},
	        {data: null,"render": function(data, type, row) {
	        	return "<a class='layui-btn layui-btn-small layui-btn-normal' title='管理' onclick='newTab(\""+data.act_name+"的团购\",\"${ctx}/shop/admin/group-buy/list.do?actid="+data.act_id+"\")'>管理</a>"
	        	+"&nbsp"+"<a class='layui-btn layui-btn-small layui-btn-normal' title='删除' onclick='del("+data["act_id"]+")'>删除</a>"
	        	+"&nbsp"+"<a class='layui-btn layui-btn-small layui-btn-danger' title='添加团购商品' onclick='newTab(\"添加团购\",\"${ctx}/shop/admin/group-buy/add.do?actid="+data.act_id+"\")'><i class='icon iconfont icon-llalbumshopselectorcreate'></i></a>";			
	       	}}
	     ]
	});
	 
	 
	//新增活动
	 $("#addgroupbuy").click(function(){
	   	 layer.open({
	            title:"添加活动",//标题
	            maxmin :true,//右上角可否放大缩小
	            type:2,//弹框的类型
	            shade: [0.3, '#000'],//黑色背景
	            shadeClose:false,//黑色背景是否可以点击关闭
	            content:'${ctx}/shop/admin/group-buy-act/add.do',//内容的URL
	            area:['600px','350px'],//弹框大小
	            scrollbar: false//是否允许浏览器出现滚动条
	        });
		});
});

//删除活动
function del(id){
	if(!confirm("确认删除导航栏？")){
		return;
	}
	$.ajax({
		url:ctx+"/shop/admin/group-buy-act/delete.do?act_id="+id,
		type:"post",
		dataType:"json",
		success:function(data){
			if(data.result == 1){
				$.Loading.success(data.message);
				table.ajax.url(ctx+"/shop/admin/group-buy-act/list-json.do").load();
			}
		}
	});
}

</script>
<#include '/admin/footer.html' >